import os, os.path
from tools.sdlgl import *
from tools.pathlist import *

if os.name == 'nt':
    tools=['mingw']
else:
    tools=['default']

env = Environment( 
	tools=tools, 
	CPPPATH=['#'], 
	LIBPATH=['#lib'],
	CCFLAGS=["-g"] )

opts = Options(['options.cache'], ARGUMENTS)
opts.AddOptions(PathListOption("extra_prefixes", "where some dependencies are installed"))
opts.AddOptions(PathListOption("extra_CPPPATH", "initial CPPPATH"))
add_SDL_GL_Options(opts)
opts.AddOptions(
	('YACC', 'bison location', '/usr/bin/bison'),
    )

opts.Update(env)
Help(opts.GenerateHelpText(env))
opts.Save('options.cache', env)

ParsePrefixes(env,"extra_prefixes")
if env.has_key('extra_CPPPATH'):
    env.Append( CPPPATH = env['extra_CPPPATH'].split(os.pathsep) )
config_SDL_GL(env)

Export('env config_SDL_GL')

# libraries
env.SConscript('slak/glui/SConscript', build_dir='build/glui', duplicate = 0)
env.SConscript('slak/mesh/SConscript', build_dir='build/mesh', duplicate = 0)
env.SConscript('slak/demo/SConscript', build_dir='build/demo', duplicate = 0)

# tests
env.SConscript('test/SConscript', build_dir='build/test', duplicate = 0)

# games
game_env = env.Copy()
game_env.Append(LIBS=Split('''glui SDL_ttf SDL_mixer
		              SDL_image boost_filesystem'''), 
		LIBPATH=['#lib'])
Export('game_env')

game_env.SConscript('slak/tetris/SConscript', build_dir='build/tetris', duplicate = 0)
game_env.SConscript('slak/pacman/SConscript', build_dir='build/pacman', duplicate = 0)

# packaging / installing 
if False and env['PLATFORM'] == 'darwin':
	from tools.osxbundle import *
	TOOL_BUNDLE(env)
	env.Alias("app", env.MakeBundle("Tetris.app",
					"build/tetris/tetris",
					"key",
					"slak/tetris/Info.plist",
					typecode='APPL',
					icon_file='media/bitmaps/Tetris.icns'))
	env['BUILDERS']['DiskImage'] = Builder(action = BuildDmg)
	DmgFiles = [ Dir("Tetris.app") ]
	env.Alias("dmg", env.DiskImage('Tetris.dmg', DmgFiles))


